<?php
/**
 * The implementation of Binder Factory that generates the different binding strategies. 
 */
class IOC_BinderFactoryImpl implements IOC_BinderFactory {
	private $className;
	private $injector;
	
	public function __construct($className, IOC_Injector $injector) {
	    if(empty($className)) {
	        throw new IOC_BindingException("The class name to bind is null or empty.");
	    }
		$this->className = $className;
		$this->injector = $injector;
	}

    /**
     * The class name to use as an implementation
     * @param $className
     */
	public function to($className) {
	    if(empty($className)) {
	        throw new IOC_BindingException("The binded class name is null or empty.");
	    }
	    $binder = new IOC_TreeBinder($className);
		$this->injector->addBinder($this->className, $binder);
		return $binder;
	}
	
	/**
	 * An instance to use as an implementation
	 * @param $object
	 */
	public function toInstance($object) {
	    if(is_null($object)) {
	        throw new IOC_BindingException("The instance binded is null.");
	    }
		$this->injector->addBinder($this->className, new IOC_InstanceBinder($object));
	}
	
	/**
	 * A provider to use as an implementation
	 * @param $provider
	 */
	public function toProvider(IOC_Provider $provider) {
	    if(is_null($provider)) {
	        throw new IOC_BindingException("The provider binded is null.");
	    }
	    $binder = new IOC_ProviderBinder($this->className, $provider);
		$this->injector->addBinder($this->className, $binder);
		return $binder;
	}
}
?>